package cn.com.dhcc.app.pub.core.util;

import javax.sql.rowset.serial.SerialException;

import org.apache.log4j.Logger;

import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.core.util.DESCoder;
/**
 * turbo解密解密util
 * @author qiao
 * @2015-1-9 @下午2:04:39
 */
public class TurboCryptUtil {

	private static final Logger log = Log.getLogger(LOGTYPE.TURBO);
	/**
	 * 创建验证码
	 * @return
	 */
	public static String createAuthCode(){
		return "";
	}
	/*
	*//**
	 * 授权码解码
	 * @param adapterCode 适配器编码
	 * @param authCode 授权码
	 * @return
	 * @throws SerialException 
	 *//*
	public static String deCodeAuthCode(String adapterCode,String encryptAuthCode) throws ServiceException{
		try {
		    String outputStr = DESCoder.decryptString(adapterCode, encryptAuthCode);
			return outputStr;
		} catch (Exception e) {
			log.error(e);
			throw new ServiceException("解密授权码失败",e);
		}
	}*/
	/**
	 * 发送数据加密
	 * @param sysCode 发送端系统编码
	 * @param authCode 授权码
	 * @return
	 * @throws ServiceException 
	 * @throws SerialException 
	 */
	public static String enCodeData(String sysCode,String data) throws ServiceException{
		try {
			String outputStr = DESCoder.encryptString(sysCode, data);
			return outputStr;
		} catch (Exception e) {
			log.error(e);
			throw new ServiceException("加密数据失败",e);
		}
	}
	/**
	 * 发送数据解码
	 * @param adapterCode 适配器编码
	 * @param authCode 授权码
	 * @return
	 * @throws SerialException 
	 */
	public static String deCodeData(String sysCode,String data) throws ServiceException{
		try {
		    String outputStr = DESCoder.decryptString(sysCode, data);
			return outputStr;
		} catch (Exception e) {
			log.error(e);
			throw new ServiceException("解密数据失败",e);
		}
	}
	/**
	 * 授权码加密
	 * @param sysCode 发送端系统编码
	 * @param authCode 授权码
	 * @return
	 * @throws ServiceException 
	 * @throws SerialException 
	 *//*
	public static String enCodeAuthCode(String adapterCode,String unencryptAuthCode) throws ServiceException{
		try {
			String outputStr = DESCoder.encryptString(adapterCode, unencryptAuthCode);
			return outputStr;
		} catch (Exception e) {
			log.error(e);
			throw new ServiceException("加密授权码失败",e);
		}
	}*/
//	public static void main(String[] args) throws ServiceException {
//		String src = "000000100001_10.10.116.74";   
//		String adapterCode = "000000100001";
//		String afterCode = enCodeData(adapterCode, src);
//		System.out.println("授权码加密后："+afterCode);
//		String beforeCode = deCodeData(adapterCode, afterCode);
//		System.out.println("授权码解密后："+beforeCode);
//		System.out.println("远明文和解密后是否相同："+Md5Util.encrypt(src).equals(Md5Util.encrypt(beforeCode)));
//	}
}
